﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Generic;
using Exceptions;
using System.IO;
using BetFairProjectUK;
using BetFairGlobal;
namespace BetFairProject
{
   class Program
   {
      public static List<int> EventTypeFilter = new List<int>(){1,2};
      static void Main(string[] args)
      {
		
		   string password = "aj261188fmar";
		   string username = "JorgeRamos";
		   BFGlobalService global = new BFGlobalService();
		   string session = Login(global,username,password);
		   List<LoginErrorEnum> errorList = Utils.EnumToList<LoginErrorEnum>();
		   APIRequestHeader header = new APIRequestHeader();
		   header.clientStamp = 0;
		   header.sessionToken = session;
		   EventsManager.header = header;
		   EventsManager.GetAllEventTypes();
		   EventType[] ourEvents = EventsManager.GetFilteredEventsArray(EventTypeFilter);
		   Event xpto = EventsManager.GetCompleteEvent(EventTypeFilter[0]);
		   UKExchangeMain.MainUK(ourEvents, session);

         
         Console.WriteLine(session);
      }

     

      private static string Login(BFGlobalService global,string user, string password)
      {
         LoginReq login = new LoginReq();
         login.ipAddress = "0";
         login.locationId = 0;
         login.productId = 82;
         login.vendorSoftwareId = 0;
         login.username = user;
         login.password = password;

         LoginResp response = global.login(login);
         if (response.errorCode != LoginErrorEnum.OK)
         {
            throw new LoginException(response.errorCode, response.header.errorCode);
         }
         
         return response.header.sessionToken;
      }
   }
}

namespace Exceptions
{
   public class LoginException : Exception
   {
      private LoginErrorEnum loginErrorEnum;
      private BetFairGlobal.APIErrorEnum aPIErrorEnum;

      public LoginException(LoginErrorEnum loginErrorEnum, BetFairGlobal.APIErrorEnum aPIErrorEnum)
      {
         // TODO: Complete member initialization
         this.loginErrorEnum = loginErrorEnum;
         this.aPIErrorEnum = aPIErrorEnum;
      }
   }
}
